package demoMod.nanaki.powers;

import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.AbstractPower;
import demoMod.nanaki.NanakiMod;

import java.util.stream.Collectors;

public class FoverPowderPower extends AbstractPower {
    public static final String POWER_ID = NanakiMod.makeID("FoverPowderPower");
    private static final PowerStrings powerStrings;
    public static final String NAME;
    public static final String[] DESC;

    public FoverPowderPower(AbstractCreature owner, int amount) {
        this.name = NAME;
        this.ID = POWER_ID;
        this.owner = owner;
        this.amount = amount;
        this.updateDescription();
        this.loadRegion("hymn");
    }

    @Override
    public void updateDescription() {
        if (owner instanceof AbstractPlayer) {
            this.description = String.format(DESC[0], this.amount);
        } else {
            this.description = String.format(DESC[1], this.amount);
        }
    }

    @Override
    public int onAttacked(DamageInfo info, int damageAmount) {
        if (info.type == DamageInfo.DamageType.NORMAL && info.owner != this.owner && damageAmount > 0) {
            this.flash();
            if (owner instanceof AbstractPlayer) {
                for (AbstractMonster monster : AbstractDungeon.getCurrRoom().monsters.monsters.stream().filter(m -> !m.isDeadOrEscaped()).collect(Collectors.toList())) {
                    addToBot(new ApplyPowerAction(monster, owner, new NotePower(monster, this.amount)));
                }
            } else {
                addToBot(new ApplyPowerAction(AbstractDungeon.player, owner, new NotePower(AbstractDungeon.player, this.amount)));
            }
        }
        return damageAmount;
    }

    @Override
    public void playApplyPowerSfx() {
        CardCrawlGame.sound.play("SPORE_CLOUD_RELEASE");
    }

    static {
        powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
        NAME = powerStrings.NAME;
        DESC = powerStrings.DESCRIPTIONS;
    }
}
